package cn.wolfcode.crm.service.impl;

import cn.wolfcode.crm.domain.Product;
import cn.wolfcode.crm.mapper.DicitemMapper;
import cn.wolfcode.crm.mapper.ProductMapper;
import cn.wolfcode.crm.query.QueryObject;
import cn.wolfcode.crm.service.IProductService;
import cn.wolfcode.crm.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
public class ProductServiceImpl implements IProductService {

    @Autowired
    private ProductMapper productMapper;

    @Autowired
    private DicitemMapper dicitemMapper;
    @Override
    public int deleteByPrimaryKey(Long id) {
        return productMapper.deleteByPrimaryKey(id);
    }


    @Override
    public Product selectByPrimaryKey(Long id) {
        return productMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<Product> selectAll() {
        return productMapper.selectAll();
    }

    @Override
    public int insert(Product entity) {
        return productMapper.insert(entity);
    }

    public int updateByPrimaryKey(Product entity, String promissgroupnmae,Long ids) {

        //dicitemMapper.updateByPromiss(promissgroupnmae,entity.getPromise().getId());
        return productMapper.updateByPrimaryKey(entity);
    }

    @Override
    public List<Product> selectNomal() {
        return productMapper.selectNomal();
    }

    @Override
    public void changeState(Long id) {
        productMapper.changeState(id);
    }

    //分页
    public PageResult query(QueryObject qo) {
        int total = productMapper.query4Count(qo);
        if (total == 0) {
            return new PageResult(0, Collections.EMPTY_LIST);
        }
        List<?> rows = productMapper.query4List(qo);
        return new PageResult(total, rows);
    }
}
